/**
 * Created by Administrator on 2018/9/8.
 */

// 报销费用明细
var afrColumnsCCBX = [{
    id: 'trCompanyName',
    title: '报销主体公司',
    width: 150,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'triClassName',
    title: '报销类目',
    width: 150,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'money',
    title: '金额',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'startDate',
    title: '开始日期',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    hideType: 'lg|md|sm|xs',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var date = new Date(record.startDate);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd hh:mm");
        return content;
    }
}, {
    id: 'endDate',
    title: '结束日期',
    type: 'string',
    width: 150,
    columnClass: 'text-center',
    hideType: 'lg|md|sm|xs',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var date = new Date(record.endDate);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd hh:mm");
        return content;
    }
}, {
    id: 'startAddr',
    title: '开始地点',
    type: 'string',
    width: 150,
    columnClass: 'text-center',
    hideType: 'lg|md|sm|xs',
}, {
    id: 'endAddr',
    title: '结束地点',
    type: 'string',
    width: 150,
    columnClass: 'text-center',
    hideType: 'lg|md|sm|xs',
}, {
    id: 'triNum',
    title: '原始单据数量',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    hideType: 'lg|md|sm|xs',
}, {
    id: 'trInstruction',
    title: '费用报销明细说明',
    type: 'string',
    columnClass: 'text-left',
}, {
    id: 'operation',
    title: '操作',
    width: 110,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';
        content += '  ';
        content += '<button class="btn btn-xs btn-primary" onclick="disMyModal(\'' + record.triCode + '\');"><i class="icon-eye-open"></i>  项目占比</button>';
        return content;
    }
}];
var $$scope;
var triArray;
function ccbxInfoDetail($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams) {
    $$scope = $scope;
    if ($routeParams && $routeParams.trCode) {
        CertusFormAjax.ajax("ccbxInfoTrcode", {trCode: $routeParams.trCode}, function (res) {

            $scope.trEntity = res.data;

            triArray = res.data.items;
            //初始化表格
            var afrOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '报销费用明细',
                datas: res.data.items,
                columns: afrColumnsCCBX,
                gridContainer: 'afrContainer',
                toolbarContainer: 'afrToolBarContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            startGridTwo = $.fn.dlshouwen.grid.init(afrOption);
            startGridTwo.load();
        })

        $$scope.getsssbbb = function(bb){
            ;
            //starting denied sentback others completed
            if(bb == "starting"){
                return "正在进行中";
            }else if(bb == "denied"){
                return "否决";
            }else if(bb == "sentback"){
                return "被退";
            }else if(bb == "others"){
                return "关闭";
            }else if(bb == "completed"){
                return "完成";    }else if(bb == "terminated"){        return "终结";    }    else if(bb == "cancelled"){        return "通过";}
            return "待办";
        }

        CertusFormAjax.ajax("findProStepId", {trCode: $routeParams.trCode}, function (res) {

            CertusJsonAjax.ajax("queryEveryProjTrace", {
                "processInstanceId": res.data.processInstanceId,
                "stepInstanceId": res.data.stepInstanceId
            }, function (res) {
                $$scope.projs = res.data;
            })
        })

        CertusFormAjax.ajax("queryCCBXLCProcessTraceTrcode", {trCode: $routeParams.trCode}, function (res) {
            ;
            $scope.processCCBXTrace = res.data;
        })

        //
        // $CertusJsonAjax.ajax("queryEveryProjTrace",{
        //     "processInstanceId": $CertusJsonAjax.getProInstanceId(),
        //     "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
        // },function(res){
        //     $$scope.projs = res.data;
        // })

    }
}

function disMyModal(triCode) {
    ;
    for (var i in triArray) {
        if (triArray[i].triCode == triCode) {
            if (triArray[i].projectPercent) {
                codeNow = triCode;
                nowprojectPercent = triArray[i].projectPercent;
                $$scope.trItem = triArray[i];
                $$scope.nowprojectPercents = nowprojectPercent;
                $$scope.$apply();
                $("#myModal").modal('show');
                // $(".haddpro").show();
            }
        }
    }
}